package com.AFH.test;
import android.graphics.Canvas;	
import java.util.ArrayList;	

public class Sprite {
	ArrayList<int[]> animationList=new ArrayList<int[]>();
	//segment 0: move
	//segment 1: attack
	//segment 2: stop
	//segment 3: disappear
	//segment 4: empty


	//private static final int FRAMENUM=4;	
	protected int currentFrame;
	protected int currentSegment;
	//protected int attackFrame;
	protected float xPos;
	protected float yPos;
	protected float speed;//The speed of tower is 0.
	protected boolean paused=false;

	SpriteThread st;
	
	
	
	public Sprite(){
		
	}

	
	public Sprite(float xPos,float yPos){
		this.xPos=xPos;
		this.yPos=yPos;
		currentFrame=0;
		//attackFrame=0;
		st=new SpriteThread(this);
	}
	
	public void setCurrentSegment(int currentSegment) {
		this.currentSegment = currentSegment;
		this.currentFrame=0;
	}

	
	public void movefoward(){
		xPos=xPos-speed;
		if (xPos<0) xPos=0;
	}
	
	public void nextframe(){
	
		int [] currSeg = animationList.get(currentSegment);
		if(currentSegment==3 && currentFrame==currSeg.length-1) {
			//currentSegment=4;
			stopAnimation();
			return;
		}
		currentFrame = (currentFrame + 1)%currSeg.length;	
//		if(currentSegment==2){
//			attackFrame=(attackFrame+1)%(animationList.get(0).length+1);
//		}
	}
	

	
	public void makeAnimation(int ani[][]){
		for(int [] imgIds:ani){
			this.animationList.add(imgIds);
		}
	}
	
	public void drawself(Canvas canvas, int x,int y){
		
	}
	
	public void drawself(Canvas canvas){
		
	}

	public void startAnimation(){
		st.spStart = true;
		if(!st.isAlive()){
			st.start();
		}
	}
	
	public void pauseAnimation(){
		st.spStart = false;
		paused=true;
	}
	
	public void resumeAnimation(){
		if(paused){
			paused=false;
			st.spStart=true;
		}
	}
	
	public void stopAnimation(){
		st.flag = false;
		st.spStart = false;
	}


	public float getxPos() {
		return xPos;
	}

	public float getyPos() {
		return yPos;
	}



	/*public void delayedStartAnimation(long milliseconds){
		st.spStart = true;
		if(!st.isAlive()){
			st.start();
		}
	}*/
	

}
